package com.scs.application.modules.print.adapter;

import com.scs.application.modules.print.service.FieldService;
import com.scs.application.modules.print.service.TemplateService;
import com.scs.application.modules.sys.properties.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:打印模板适配器
 */
@Component
public class PrintTemplateAdapter {
    @Autowired
    private SystemProperties systemProperties;

    private List<TemplateService> templateServices;

    private List<FieldService> fieldServices;


    @Autowired
    private void setTemplateServices(List<TemplateService> templateServices) {
        this.templateServices = templateServices;
    }

    @Autowired
    private void setFieldServices(List<FieldService> fieldServices) {
        this.fieldServices = fieldServices;
    }

    /**
     * 获取当前项目的TemplateService实现类
     *
     * @return
     */
    public TemplateService getTemplateService() {
        TemplateService templateService = null;
        for (TemplateService templateService1 : templateServices) {
            if (templateService1.isSupport(systemProperties.getFlagProject())) {
                templateService = templateService1;
                break;
            }
        }
        return templateService;
    }

    /**
     * 获取当前项目的FieldService实现类
     *
     * @return
     */
    public FieldService getFieldService() {
        FieldService fieldService = null;
        for (FieldService fieldService1 : fieldServices) {
            if (fieldService1.isSupport(systemProperties.getFlagProject())) {
                fieldService = fieldService1;
                break;
            }
        }
        return fieldService;
    }

    /**
     * 获取当前项目的TemplateService实现类
     *
     * @return
     */
    public TemplateService getTemplateService(Boolean flagProject) {
        TemplateService templateService = null;
        for (TemplateService templateService1 : templateServices) {
            if (templateService1.isSupport(flagProject)) {
                templateService = templateService1;
                break;
            }
        }
        return templateService;
    }

    /**
     * 获取当前项目的FieldService实现类
     *
     * @return
     */
    public FieldService getFieldService(Boolean flagProject) {
        FieldService fieldService = null;
        for (FieldService fieldService1 : fieldServices) {
            if (fieldService1.isSupport(flagProject)) {
                fieldService = fieldService1;
                break;
            }
        }
        return fieldService;
    }
}
